#!/usr/bin/env node
// 获取权限
const fs = require("fs");
const path = require("path");
const inquirer = require("inquirer");
const ejs = require("ejs");
inquirer
  .prompt([
    {
      type: "input",
      name: "component",
      message: "请输入文件名"
    },
    {
      type: "input",
      name: "title",
      message: "请输入title"
    }
  ])
  .then(answers => {
    console.log(answers);
    const tempDir = path.join(__dirname, "templates");
    fs.readdir(tempDir, (err, files) => {
      if (err) throw err;
      files.forEach(file => {
        ejs.renderFile(path.join(tempDir, file), answers, (err, result) => {
          fs.writeFileSync(
            path.join(
              process.cwd(),
              answers.component + "." + file.split(".")[1]
            ),
            result
          );
          console.log("success");
        });
      });
    });
  });
